package com.yeung.swordoffer;

import java.util.Arrays;

public class 扑克牌顺子 {
    public static void main(String[] args) {
        int[] arr = {1, 3, 2, 6, 4};
        boolean continuous = isContinuous(arr);
        System.out.println(continuous);
    }

    //A看作1,J为11,Q为12,K为13
    public static boolean isContinuous(int[] numbers) {
        if (numbers.length < 1) return false;
        Arrays.sort(numbers);
        int changes = 0;
        boolean flag = true;
        for (int i = 0; i < numbers.length - 1; i++) {
            if (numbers[i] == 0) changes++;
            else {
                int cha = numbers[i + 1] - numbers[i] - 1;
                if (cha < 0 || cha > changes) {//是否连续,或者是否有重复数字,有即是不连续的
                    flag = false;
                    break;
                } else {
                    changes -= cha;
                    if (changes < 0) {
                        flag = false;
                        break;
                    }
                }
            }
        }
        return flag;
    }


}
